from matplotlib import pyplot as plt, animation
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
import tkinter as tk

class DynamicPointXY:
    def __init__(self,parent):
        self.parent = parent
        self.fig, self.ax = plt.subplots(1, 1, figsize=(5, 5), dpi=150)
        plt.grid(True)
        self.point, = self.ax.plot([0], [0], 'or', markersize=6)
        self.ax.set_xlim(-500, 500)  # 设置x轴的显示范围
        self.ax.set_ylim(-500, 500)  # 设置y轴的显示范围

        # 创建图形画布
        self.canvas = FigureCanvasTkAgg(self.fig, master=self.parent)

        self.appendData = [0] * 2

        self.canvas.get_tk_widget().pack(fill=tk.X)

        self.ani = animation.FuncAnimation(self.fig, self.update, interval=50, blit=False, init_func=None, repeat=False)

        self.x = 0
        self.y = 0

    def put(self, *datas):
        self.appendData=datas

    def update(self,i):

        self.x = self.appendData[0]
        self.y = self.appendData[1]

        self.point.set_xdata(self.x)
        self.point.set_ydata(self.y)

        # 省略

        return self.point,



